﻿@if (false)
{
    // Just use this script to enable jQuery intellisense in Visual Studio. Never render to real HTML.
    <script src="/Scripts/jquery-1.5.1-vsdoc.js" type="text/javascript"></script>
}
@using ORM.Models
@model ORM.Areas.Admin.ViewModels.ManageSpam.ListReportedQuestionViewModel        
@{
    ViewBag.Title = "Manage Spam";
    ViewBag.MenuGroup = "Spam";
    ViewBag.MenuName = "ManageReportedQuestions";
    ViewBag.PageHeader = "Manage Reported Questions";
}
@Html.ValidationSummary(true, ValidationMessages.Summary)
@using (Html.BeginForm("ManageReportedQuestion", "ManageSpam", FormMethod.Get))
        {
            <div class="input">
                <div>
                    @Html.ValidationMessageFor(o => o.MinReportNumber)
                </div>
                <p>
                   <label class = "filter-label">Display Questions with number of reports greater than or equal to:</label>
                    @Html.TextBoxFor(o => o.MinReportNumber, new { name = "minReportNumber" })
                    <button type="submit">Filter</button>
                </p>
            </div>   
        } 
 
@(Html.Telerik().Grid(Model.ReportedQuestions)
           .Name("Questions")
           .DataKeys(dataKeys => dataKeys.Add(c => c.Id))
           .Columns(columns =>
           {
               columns.Template(
                   @<text>
                        <a href="/Question/Details/@item.Id">@item.Title</a>                                          
                    </text>    
               ).Width("350px").Title("Title");
               columns.Template(
                   @<text>
                        <a href="/admin/ManageUsers/Details/@item.PostedBy.Id">@item.PostedBy.Username</a>    
                    </text>
               ).Width("120px").Title("Posted By");
               columns.Bound(o => o.PostedDate).Format("{0:dd/MM/yyyy}").Width("100px");
               columns.Template(
                   @<text>
                        <a class="view-reports"><u>@item.Reports</u></a>
                        <input type="hidden" value="@item.Id" class="id" />
                   </text>
                ).Width("80px").Title("Reports");
               columns.Template(
                  @<text>
                        @Html.Partial("_FalseReportButton", new ActionInfo("Not spam", "DeleteFalseQuestionReports") { Id = item.Id })
                        @Html.Partial("_DeleteButton", new ActionInfo("Delete", "DeleteReportedQuestion") { Id = item.Id })
                  </text>
               );
           })
           .Pageable(pager => pager.PageSize(AppConfigs.DefaultAdminGridPageSize))
           .Sortable()
           .Scrollable(scrolling => scrolling.Enabled(true).Height(350))
                            )
@(Html.Telerik().Window()
        .Name("reports-window")
        .Title("Question Reports")
        .Content(
            @<text>
                <div id="report-details"></div>
            </text>
        )
        .Width(500)
        .Height(500)
        .Scrollable(true)
        .Draggable(true)
        .Modal(true)
        .Visible(false)
)

<script type="text/javascript">
    $(document).ready(function () {
        $(".view-reports").click(function (e) {
            e.preventDefault();
            var id = $("~ .id", this).val();
            $("#report-details").html("");
            $("#report-details").load("@Url.Action("QuestionReportDetails")", "id=" + id);
            $('#reports-window').data('tWindow').center().open();
        });

       $(".t-grid-delete").click(function (e) {
           if ($(this).html().indexOf("Delete") >= 0) {
                if (!confirm("Are you sure you want to delete this Question?")) {
                    return false;
                }
            }
            if ($(this).html().indexOf("False Report") >= 0) {
                if (!confirm("Are you sure you want to delete all reports belong to this Question?")) {
                    return false;
                }
            }
        });
                
    });
</script>